﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ITS.Infrastructure.Helpers
{
    public class CryptographyHelper
    {
        public static string ToMD5(string s)
        {
            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrEmpty(s))
            {
                MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
                byte[] myPass = System.Text.Encoding.UTF8.GetBytes(s);
                myPass = mD5CryptoServiceProvider.ComputeHash(myPass);

                foreach (byte p in myPass)
                {
                    sb.Append(p.ToString("x2").ToLower());
                }
            }
            return sb.ToString();
        }
    }
}
